/*
 * @Author: fuhongliang-TSJ hongliang.fu@4d-bios.com
 * @Date: 2025-08-15 13:04:02
 * @LastEditTime: 2025-08-19 15:19:53
 * @LastEditors: fuhongliang-TSJ hongliang.fu@4d-bios.com
 * @Description: 
 * @FilePath: \lc_-esp32_-s3\components\bsp\cmd\cmd_user\cmd_user.c
 * 立创实战派ESP32-S3开发板
 * Copyright (c) 2025 by 4D Bios, All Rights Reserved. 
 */

#include <stdio.h>
#include "argtable3/argtable3.h"
#include "driver/i2c.h"
#include "esp_console.h"
#include "esp_log.h"

static const char *TAG = "cmd_system_user";

static void register_test(void);

static struct {
    struct arg_int *index;
    struct arg_str *str;
    struct arg_end *end;
} test_args;

void register_user(void)
{
    register_test();
}

/** 'test' command */

static int test(int argc, char **argv)
{
    int nerrors = arg_parse(argc, argv, (void **) &test_args);

    if (nerrors != 0) {
        arg_print_errors(stderr, test_args.end, argv[0]);
        return 1;
    }

    int index = 0;
    const char* str = NULL;

    index = (uint8_t)(test_args.index->ival[0]);
    str = test_args.str->sval[0];

    ESP_LOGI(TAG, "Test");

    if(test_args.index->count)
        ESP_LOGI(TAG, "you input is: index->%d, str->%s", index, str);
    else    
        ESP_LOGI(TAG, "you input is: str->%s", str);

    return 0;
}

static void register_test(void)
{
    test_args.index = arg_int0("n", "number", "<test int>", "a int value");         // 可选整数参数
    test_args.str = arg_str1("s", "string", "<test string>", "a string value");     // 可选整数参数
    test_args.end = arg_end(2);    // 参数列表结束, 最多允许有 2 个额外的未解

    const esp_console_cmd_t cmd = {
        .command = "test",
        .help = "test print test",
        .hint = NULL,
        .func = &test,
        .argtable = &test_args,
    };
    ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
}